

*-------------------------------------------------------------------------------
* collect data 
*-------------------------------------------------------------------------------

* isr data
use "data/outputs/ISRpedestrian_beat.dta", clear
collapse (sum) isr_*, by(month)
tempfile isr
save `isr'

* contact card data
use "data/outputs/CC_beat.dta", clear
collapse (sum) pedestrian*, by(month)
renvars pedestrian*, prefix(cc_)
tempfile cc
save `cc'

* traffic stop data
use "data/outputs/TSSS_beat.dta", clear
keep if agencyname == "CHICAGO POLICE"
collapse (sum) count black hispanic citation count_racenonmiss, by(month)
renvars count* black hispanic citation, prefix(itss_)

* merge
merge 1:1 month using `cc'
drop if _m == 2 /* 2009–2011, 2022 */
drop _m
merge 1:1 month using `isr'
drop _m


*-------------------------------------------------------------------------------
* calculate percentages
*-------------------------------------------------------------------------------

* pedestrian series: contact card data pre 2016, ISR data in 2016+
gen pedestrian = cc_pedestrian
replace pedestrian = isr_count_pedestrian if month >= tm(2016m1)
gen pedestrian_hispanic = cc_pedestrian_hispanic
replace pedestrian_hispanic = isr_hispanic_pedestrian if month >= tm(2016m1)

* pedestrian percent hispanic
gen pedestrian_pcthispanic = pedestrian_hispanic / pedestrian

* traffic percent black
gen tsss_pcthispanic = itss_hispanic / itss_count

* total fraction black 
gen stops_total = pedestrian + itss_count 
gen hispanic_total = pedestrian_hispanic + itss_hispanic 
gen pcthispanic_allstops = hispanic_total / stops_total

* shaded region
gen treatment = 1 if month >= tm(2015m8) & month <= tm(2016m1)


*-------------------------------------------------------------------------------
* graph
*-------------------------------------------------------------------------------

#delimit;
twoway (area treatment month if month <= tm(2020m2), 
		lcolor(gs15%100) fcolor(gs15%100))
	(connected pedestrian_pcthispanic month if month < tm(2020m3), 
		lcolor(gs11%10) mcolor(gs11%50) msize(vsmall))	
	(connected tsss_pcthispanic month if month < tm(2020m3),
		lcolor(blue%50) mcolor(blue%50) msize(vsmall))
	(connected pcthispanic_allstops month if month < tm(2020m3), 
		lcolor(red) mcolor(red) msymbol(diamond) msize(small)),
graphregion(fcolor(white) lcolor(white) margin(zero))
plotregion(fcolor(white) lstyle(none) lcolor(white) ilstyle(none))
xsize(7) ysize(5)
title("", 
	  color(black) placement(west) justification(left) size(medlarge)) 
ytitle("Proportion of Stopped People Who Are Hispanic", size(medlarge))
yscale(lcolor(none) )
ylabel(0(.2)1, labsize(large) glcolor(white) angle(horizontal))
xtitle("", size(medsmall)) 
xscale(lcolor(none) range(636 722) )
xlabel(624(12)720, labsize(medlarge) format(%tmCY)) 
legend(order(2 "Pedestrian stops" 4 "All stops" 3 "Traffic stops")
rows(3) pos(2) ring(0) size(medlarge) symxsize(*.5));
graph export "figures/FigureS1.pdf", replace;
#delimit cr

* End

